home *** CD-ROM | disk | FTP | other *** search
/ Celestin Apprentice 5 / Apprentice-Release5.iso / Source Code / C / Applications / Moscow ML 1.31 / source code / mosml / e_mac / momlmenus.c < prev    next >
Encoding:
C/C++ Source or Header  |  1995-10-20  |  4.0 KB  |  167 lines  |  [TEXT/CWIE]

  1. #include <Files.h>
  2. #include <StdLib.h>
  3. #include <Resources.h>
  4. #include <StandardFile.h>
  5. #include "ui.h"
  6. #if defined( THINK_C ) || defined( __MWERKS__ )
  7. #include <stdio.h>
  8. #include <string.h>
  9. #include <strings.h>
  10. #endif
  11.  
  12. void CenterRect (Rect *r);
  13.  
  14. /* 09Jan95 e */
  15. static FileFilterUPP compile_filterUPP = NULL;
  16. static FileFilterUPP source_filterUPP = NULL;
  17. static FileFilterUPP object_filterUPP = NULL;
  18.  
  19. static pascal Boolean compile_filter (ParmBlkPtr pb)
  20. {
  21.   char len = pb->fileParam.ioNamePtr [0];
  22.   if (len >= 4
  23.       && pb->fileParam.ioNamePtr [len    ] == 'l'
  24.       && pb->fileParam.ioNamePtr [len - 1] == 'm'
  25.       && pb->fileParam.ioNamePtr [len - 2] == 's'
  26.       && pb->fileParam.ioNamePtr [len - 3] == '.'){
  27.     return 0;
  28.   }else if (len >= 4
  29.       && pb->fileParam.ioNamePtr [len    ] == 'g'
  30.       && pb->fileParam.ioNamePtr [len - 1] == 'i'
  31.       && pb->fileParam.ioNamePtr [len - 2] == 's'
  32.       && pb->fileParam.ioNamePtr [len - 3] == '.'){
  33.     return 0;
  34.   }else{
  35.     return 1;
  36.   }
  37. }
  38.  
  39. static pascal Boolean source_filter (ParmBlkPtr pb)
  40. {
  41.   char len = pb->fileParam.ioNamePtr [0];
  42.   if (len >= 4
  43.       && pb->fileParam.ioNamePtr [len    ] == 'l'
  44.       && pb->fileParam.ioNamePtr [len - 1] == 'm'
  45.       && pb->fileParam.ioNamePtr [len - 2] == 's'
  46.       && pb->fileParam.ioNamePtr [len - 3] == '.'){
  47.     return 0;
  48.   }else{
  49.     return 1;
  50.   }
  51. }
  52.  
  53. static pascal Boolean object_filter (ParmBlkPtr pb)
  54. {
  55.   char len = pb->fileParam.ioNamePtr [0];
  56.   if (len >= 3
  57.       && pb->fileParam.ioNamePtr [len    ] == 'o'
  58.       && pb->fileParam.ioNamePtr [len - 1] == 'u'
  59.       && pb->fileParam.ioNamePtr [len - 2] == '.'){
  60.     return 0;
  61.   }else{
  62.     return 1;
  63.   }
  64. }
  65.  
  66. static char postfix [] = ":";
  67. #ifdef THINK_C
  68. static char nocd_template [] = "%s \"%#s\";";
  69. static char cd_template [] = "chDir \"%s\"; %s \"%#s\";";
  70. #else
  71. static char nocd_template [] = "%s \"%s\";";
  72. static char cd_template [] = "chDir \"%s\"; %s \"%s\";";
  73. #endif
  74.  
  75. static void do_file (char *command, long type, FileFilterUPP filter)
  76. {
  77.   SFTypeList type_list;
  78.   StandardFileReply reply;
  79.   short cur_vol;
  80.   long cur_dir;
  81.   char *buf, dir[512];
  82.   
  83.   type_list [0] = type;
  84.   StandardGetFile ( filter, 1, type_list, &reply );
  85.   if (!reply.sfGood) return;
  86. #ifndef THINK_C
  87.   p2cstr (reply.sfFile.name);
  88. #endif
  89.   HGetVol( NULL, &cur_vol, &cur_dir ); // 30Aug95 e
  90.   if ( cur_vol == reply.sfFile.vRefNum && cur_dir == reply.sfFile.parID )
  91.   { buf = malloc (sizeof (nocd_template) - 4
  92.           + strlen (command)
  93. #ifdef THINK_C
  94.           + reply.sfFile.name[0]);
  95. #else
  96.           + strlen ((char *)reply.sfFile.name));
  97. #endif
  98.     if (buf == NULL) return;
  99.     sprintf (buf, nocd_template, command, reply.sfFile.name);
  100.   }else{
  101.     // dir = get_wd_name (reply.sfFile.vRefNum, postfix);
  102.     getfullpath( reply.sfFile.vRefNum,
  103.                  reply.sfFile.parID,
  104.                  "\p", // postfix unnecessary
  105.                  dir, 511, 0 );
  106.     buf = malloc (sizeof (cd_template) - 6
  107.           + strlen (dir)
  108.           + strlen (command)
  109. #ifdef THINK_C
  110.           + reply.sfFile.name[0]);
  111. #else
  112.           + strlen ((char *)reply.sfFile.name));
  113. #endif
  114.     if (buf == NULL) return;
  115.     sprintf (buf, cd_template, dir, command, reply.sfFile.name);
  116.     // if (dir != postfix) free (dir - 1);           /* cf.get_wd_name */
  117.   }
  118.   send_to_caml (buf);
  119.   free (buf);
  120. }
  121.  
  122. static ensure_ff_upp (void)
  123. { if ( compile_filterUPP == NULL )
  124.   { compile_filterUPP = NewFileFilterProc(compile_filter);
  125.     source_filterUPP  = NewFileFilterProc(source_filter);
  126.     object_filterUPP  = NewFileFilterProc(object_filter);
  127.   }
  128. }
  129.  
  130. void do_include (void)
  131. {
  132.   ensure_ff_upp();
  133.   do_file ("use", 'TEXT', source_filterUPP);
  134. }
  135.  
  136. void do_compile (void)
  137. {
  138.   ensure_ff_upp();
  139.   do_file ("compile", 'TEXT', compile_filterUPP);
  140. }
  141.  
  142. void do_load (void)
  143. {
  144.   ensure_ff_upp();
  145.   do_file ("loadOne", 'BINA', object_filterUPP);
  146. }
  147.  
  148. void do_load_object (void)
  149. {
  150.   ensure_ff_upp();
  151.   do_file ("load", 'BINA', object_filterUPP);
  152. }
  153.  
  154. void do_gc (void)
  155. {
  156. #if 0
  157.   send_to_caml ("gc_full_major();");
  158. #else
  159.   send_to_caml("local prim_val gc : unit -> unit = 1 \"gc_full_major\" in val _ = gc() end;");
  160. #endif
  161. }
  162.  
  163. void do_help (void)
  164. {
  165.   send_to_caml ("help \"\";");
  166. }
  167.